package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.MealMapper;
import com.itheima.pojo.Meal;
import com.itheima.service.MealService;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class MealServiceImpl implements MealService  {
    @Autowired
    private MealMapper mealDao;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();

         PageHelper.startPage(currentPage,pageSize);
         Page<Meal> page=mealDao.findPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Meal meal) {
        mealDao.add(meal);
    }

    @Override
    public void delete(Integer mealId) {
        mealDao.deleteById(mealId);
    }

    @Override
    public Meal findById(Integer mealId) {
       Meal find=mealDao.findById(mealId);

        return find;
    }

    @Override
    public void update(Meal meal) {
        mealDao.update(meal);
    }
}
